﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Projektarbete
{
    /// <summary>
    /// Creates a new inventory for a player
    /// </summary>
    class EquipInventory
    {
        LinkedList<Item> contents;
        public LinkedList<Item> GetContentsAsLinkedList { get { return contents; } }
        public Item[] GetContentsAsArray { get { return contents.ToArray(); } }

        /// <summary>
        /// Creates a new equip backpack
        /// </summary>
        public EquipInventory()
        {
            contents = new LinkedList<Item>();
        }

        /// <summary>
        /// Checks if the bag contains an item
        /// </summary>
        /// <param name="item">Item to check</param>
        /// <returns></returns>
        public bool Contains(Item item)
        {
            return contents.Contains(item);
        }

        public bool ContainsType(ItemTypes type)
        {
            foreach (Item item in contents)
                if (item.getType == type)
                    return true;

            return false;
        }

        public Item GetItemFromType(ItemTypes type)
        {
            foreach (Item item in contents)
                if (item.getType == type)
                    return item;

            return new ItemPresets.EmptySlot();
        }

        /// <summary>
        /// Adds an item to the backpack if it doesn't exceed the max weight/size. Return true if sucessfully added. Does not display any notification
        /// </summary>
        /// <param name="item">Item to add</param>
        /// <returns>If sucessfully added</returns>
        public void AddItem(Item item)
        {
            if (!ContainsType(item.getType))
            {
                contents.AddLast(item);
                HUD.AddNotification(new Notification(item.getName + " equipped", NotificationColor.AddItem, NotificationLifetime.AddItem));
            }
            else
            {
                if(Player.inventory.getCurrentSize
            }
        }

        /// <summary>
        /// Removes a single item from the backpack
        /// </summary>
        /// <param name="item">Item to remove</param>
        public void RemoveItem(Item item)
        {
            if (contents.Contains(item))
            {
                contents.Remove(item);
                HUD.AddNotification(new Notification(item.getName + " unequipped", NotificationColor.RemoveItem, NotificationLifetime.RemoveItem));
            }
        }
    }
}
